package com.example.springcloudexamineserver.controller;


import com.example.springcloudexamineserver.config.WebSocketServer;
import com.example.springcloudexamineserver.entity.Model;
import com.example.springcloudexamineserver.service.ExamineService;
import com.example.springcloudexamineserver.service.ExecutePython;
import lombok.extern.slf4j.Slf4j;
import org.apache.ibatis.annotations.Mapper;
import org.apache.ibatis.annotations.Param;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.http.ResponseEntity;
import org.springframework.web.bind.annotation.*;
import org.springframework.web.client.RestTemplate;
import org.springframework.web.servlet.ModelAndView;

import javax.annotation.Resource;
import javax.ws.rs.POST;
import java.io.IOException;

@RestController
@Slf4j
@RequestMapping("/examine")
@ResponseBody
@CrossOrigin
public class ExamineController {
    @Autowired
    private ExamineService examineService;

    @Autowired
    private RestTemplate restTemplate;


    @GetMapping("index")
    public ResponseEntity<String> index(){
        return ResponseEntity.ok("请求成功");
    }

    @GetMapping("page")
    public ModelAndView page(){
        return new ModelAndView("websocket");
    }

    @RequestMapping("/push/{toUserId}")
    public ResponseEntity<String> pushToWeb(String message, @PathVariable String toUserId) throws IOException {
        WebSocketServer.sendInfo(message,toUserId);
        return ResponseEntity.ok("MSG SEND SUCCESS");
    }

    @PostMapping("/updateSimility")
    public String updateSimility(@RequestParam("modelid") String modelid) throws InterruptedException {
        String simility = ExecutePython.result;
        System.out.println(simility);
        examineService.addSimility(simility,modelid);
//        return examineService.querySimilityById(modelid);
        return simility;
    }


    }
